package com.zzyl.nursing.controller.member;

import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.dto.member.ElderMemberDto;
import com.zzyl.nursing.service.IAlertRuleService;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.vo.DeviceDataGraphVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.member.MyMemberVo;
import com.zzyl.nursing.vo.member.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.service.IFamilyMemberService;

import java.util.List;


/**
 * 老人家属Controller
 * 
 * @author alexis
 * @date 2025-05-30
 */
@Api(tags = "老人家属管理")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return success(loginVo);
    }
    @PostMapping("/add")
    public AjaxResult addFamily(@RequestBody ElderMemberDto elderMemberDto){
        familyMemberService.addFamily(elderMemberDto);
        return success();
    }

    @GetMapping("/my")
    public AjaxResult myMember(){
        List<MyMemberVo> list =familyMemberService.selectMyMember();
        return success(list);
    }

    @GetMapping("/list-by-page")
    public AjaxResult queryPage(Integer pageNum,Integer pageSize){
        List<PageResult>list=familyMemberService.queryPage(pageNum,pageSize);
        return success(list);
    }
    @GetMapping("/queryServiceProperties/{iotId}")
    public AjaxResult queryServiceProperties (@PathVariable String iotId){
        return success(familyMemberService.queryServiceProperties(iotId));
    }


    @Autowired
    private IDeviceDataService deviceDataService;

    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(
            String iotId,String functionId,Long startTime,Long endTime
    ){
        List<DeviceDataGraphVo> list = deviceDataService.queryDeviceDataListByDay(iotId,functionId,startTime,endTime);
        return success(list);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(
            String iotId,String functionId,Long startTime,Long endTime
    ){
        List<DeviceDataGraphVo> list = deviceDataService.queryDeviceDataListByWeek(iotId,functionId,startTime,endTime);
        return success(list);
    }
}
